var URLHelper = {};
URLHelper.prefixUrl = location.protocol + "//" + location.host + '/';

URLHelper.loginURL = function() {
    return this.prefixUrl + 'account/doLogin';
}

URLHelper.querypwdURL = function() {
    return this.prefixUrl + 'personal/querypwd';
}

URLHelper.insertuserURL = function() {
    return this.prefixUrl + 'admin/insertuser';
}

URLHelper.updateuserURL = function() {
    return this.prefixUrl + 'admin/updateuser';
}

URLHelper.deleteUserURL = function() {
    return this.prefixUrl + 'admin/deleteuser';
}


URLHelper.resetpwdURL = function() {
    return this.prefixUrl + 'admin/resetPwd';
}

URLHelper.user = function(url) {
    return this.prefixUrl + url;
}

URLHelper.ajax = function(url, method, data, callback, errorFun) {
    var self = this;
    if (typeof url === 'string') {
        $.ajax({
            'url' : url,
            'method' : method,
            'dataType' : 'json',
            'data': data,
            'success': function(data) {
                $('.errStyle').remove();
                callback(data);
            },
            'complete': function(req) {
                if(req.status == 401) {
                    window.location.href = self.loginURL();
                }
            },
            'error': errFun
        });
    } else if  (typeof  url === 'object') {
        if (!url['complete']) {
            url['complete'] = function(req) {if(req.status == 401) {  window.location.href = self.toLoginUrl() ;}}
        }
        url['error'] = errFun;
        var originFuc = url['success'];
        url['success'] = function(data) {
            $('.errStyle').remove();
            originFuc(data);
        }
        $.ajax(url);
    } else {
        alert('非法参数');
    }
}

function errFun(err) {
    var str = '';
    if(err.responseText != '') {
        str = '服务器发生了错误';
        console.log(err);
    } else {
        str = "网络连接异常";
    }
    notie.alert(3, str, 2);
}




